home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / Frontier / Frontier SDK 2.1 / Toolkits / Applet Toolkit / appletmouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-11  |  2.6 KB  |  110 lines  |  [TEXT/KAHL]

  1.  
  2. /*© Copyright 1988-1992 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5. #include "appletdefs.h"
  6. #include "appletmouse.h"
  7.  
  8.  
  9. tymouserecord mousestatus;
  10.  
  11.  
  12. boolean mousetrack (Rect r, tymousetrackcallback displaycallback) {
  13.     
  14.     /*
  15.     hang out in this routine until the mouse button comes up.  return true if
  16.     the mouse point is in the indicated rectangle when we return.
  17.     
  18.     7/17/90 DW: if the mouse wasn't down when we enter, return true.  this is
  19.     a heuristic that may allow some mouse-dependent routines to be driven by
  20.     a script.  we figure that if the mouse isn't down now, it never was down,
  21.     and whether it's inside any particular rectangle is irrelevent.
  22.     
  23.     7/17/90 DW: add callback routine to display the object being tracked as
  24.     the mouse moves in and out of the rectangle.  set it to nil if you don't
  25.     need this feature.
  26.     
  27.     7/17/90 DW: only call the callback when the state of the object changes,
  28.     assume display is correct when we're entered.
  29.     */
  30.     
  31.     boolean flinrectnow;
  32.     boolean flwasinrect;
  33.     
  34.     if (!StillDown ()) /*see comment above*/
  35.         return (true);
  36.     
  37.     flwasinrect = true; /*at least for the first iteration of loop*/
  38.     
  39.     while (StillDown ()) { /*stay in holding pattern*/
  40.     
  41.         Point pt;
  42.         
  43.         GetMouse (&pt);
  44.     
  45.         flinrectnow = PtInRect (pt, &r);
  46.         
  47.         if (flinrectnow != flwasinrect) { /*state of object changed*/
  48.         
  49.             if (displaycallback != nil)
  50.                 (*displaycallback) (flinrectnow);
  51.             }
  52.             
  53.         flwasinrect = flinrectnow;
  54.         } /*while*/
  55.     
  56.     return (flwasinrect);
  57.     } /*mousetrack*/
  58.  
  59.  
  60. static short absint (short x) {
  61.     
  62.     if (x < 0)
  63.         x = -x;
  64.         
  65.     return (x);
  66.     } /*absint*/
  67.     
  68.     
  69. static short pointdist (Point pt1, Point pt2) {
  70.     
  71.     return (absint (pt1.h - pt2.h) + absint (pt1.v - pt2.v));
  72.     } /*pointdist*/
  73.  
  74.  
  75. boolean mousedoubleclick (Point pt) {
  76.  
  77.     /*
  78.     using the globals mouseuptime and mouseuppoint determine if a
  79.     mouseclick at pt, right now, is a double click.
  80.     
  81.     dmb 9/6/90:  pt parameter is no longer used.  superceeded by new 
  82.     mousedown globals
  83.     */
  84.     
  85.     register boolean fldoubleclick;
  86.     register short diff;
  87.     
  88.     fldoubleclick = (mousestatus.mousedowntime - mousestatus.mouseuptime) < GetDblTime ();
  89.     
  90.     if (fldoubleclick) { /*qualifies so far*/
  91.         
  92.         diff = pointdist (mousestatus.mousedownpoint, mousestatus.mouseuppoint);
  93.         
  94.         fldoubleclick = diff < 5; /*keep it set if mouse hasn't wandered too far*/
  95.         }
  96.     
  97.     if (fldoubleclick) { /*user must doubleclick again to get effect*/
  98.         
  99.         mousestatus.mouseuptime = 0L;
  100.         
  101.         mousestatus.mouseuppoint.h = mousestatus.mouseuppoint.v = 0;
  102.         }
  103.     
  104.     mousestatus.fldoubleclickdisabled = fldoubleclick; /*copy into global*/
  105.     
  106.     return (fldoubleclick);
  107.     } /*mousedoubleclick*/
  108.  
  109.  
  110.